import axios from 'axios'
// import { Message } from 'element-ui'
// import store from '@/store/index.js'
const request = axios.create({
  baseURL: 'http://likede2-admin.itheima.net/likede/',
  timeout: 50000 // request timeout
})

// 请求拦截器
request.interceptors.request.use(
  (config) => {
    // if (!config.headers.Authorization && store.state.user.token) {
    //   config.headers.Authorization = `Bearer ${store.state.user.token}`
    // }
    const token = window.localStorage.getItem('token')
    config.headers.Authorization = token
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

// 响应拦截器
request.interceptors.response.use(
  // (res) => {
  //   return res
  // },
  // (err) => {
  //   return Promise.reject(err)
  // }
  (response) => {
    // const { message, success } = response.data;
    return response.data
    // Message.error(message)
    // return Promise.reject(message)
  },
  (error) => {
    return Promise.reject(error)
  }
)

export default request
